package com.laow.action;

import com.laow.entity.EbookCategory;
import com.laow.entity.EbookEntry;
import com.laow.service.EbookService;
import com.opensymphony.xwork2.ActionSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;


/**
 * 执行增删改页面
 */
@Controller
public class ModirAction extends ActionSupport {

    @Autowired
    @Qualifier("ebookServiceImpl")
    private EbookService ebookService;


    private int ids;      // 根据id进行删除

    private EbookEntry ebookEntry;      // 执行修改和增加功能

    public String del() throws Exception{
        EbookEntry ebookEn = ebookService.ebookEntryToId(ids);
        boolean delbolan = ebookService.delEntryData(ebookEn);
        return "delSuced";
    }

    public String udp() throws Exception{
        EbookEntry ebookEn = ebookService.ebookEntryToId(this.ebookEntry.getId());
        ebookEntry.setEbookCategorys(ebookEn.getEbookCategorys());
        boolean udpbol = ebookService.udpEntryData(this.ebookEntry);
        return "udpSuced";
    }

    public String add() throws Exception{
        EbookCategory ebookCategory=new EbookCategory();
        ebookCategory.setId(4);
        ebookEntry.setEbookCategorys(ebookCategory);
        ebookService.addEntryData(ebookEntry);
        return "addSuced";
    }


    public int getId() {
        return ids;
    }

    public void setId(int ids) {
        this.ids = ids;
    }

    public EbookEntry getEbookEntry() {
        return ebookEntry;
    }

    public void setEbookEntry(EbookEntry ebookEntry) {
        this.ebookEntry = ebookEntry;
    }
}
